# -*- coding: utf-8 -*-
'''
author:Cooper
date:2012.5.1
商品API

taobao.aftersale.get

taobao.item.templates.get

taobao.item.sku.get
taobao.item.skus.get
taobao.skus.custom.get

taobao.item.get
taobao.items.custom.get
taobao.items.get
taobao.items.inventory.get
taobao.items.list.get
taobao.items.onsale.get
taobao.items.search

taobao.product.get
taobao.products.get
taobao.products.search

taobao.ump.promotion.get
'''

from TopAPI.lib import *
import json

item_fields='detail_url,num_iid,title,nick,type,\
desc,skus,props_name,created,promoted_service,\
is_lightning_consignment,is_fenxiao,auction_point,property_alias,volume,\
template_id,after_sale_id,is_xinpin,sub_stock,inner_shop_auction_template_id,\
outer_shop_auction_template_id,cid,seller_cids,props,input_pids,\
input_str,pic_url,num,valid_thru,list_time,\
delist_time,stuff_status,location,price,post_fee,\
express_fee,ems_fee,has_discount,freight_payer,has_invoice,\
has_warranty,has_showcase,modified,increment,approve_status,\
postage_id,product_id,item_imgs,prop_imgs,outer_id,\
is_virtual,is_taobao,is_ex,is_timing,videos,\
is_3D,score,one_station,second_kill,auto_fill,\
violation,is_prepay,ww_status,wap_desc,wap_detail_url,\
cod_postage_id,sell_promise'

product_fields='product_id,outer_id,created,tsc,cid,\
cat_name,props,props_str,binds_str,sale_props_str,\
collect_num,name,binds,sale_props,price,\
desc,pic_url,modified,product_imgs,product_prop_imgs,\
status,level,pic_path,vertical_market,customer_props,\
property_alias'

class after_sale():
	api='taobao.aftersale.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json'):
		#self.format=format
		self.__dict__.update(locals())
	def getRes():
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseAfterSale(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'after_sales')
	pass

class template():
	api='taobao.item.templates.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseTemplate(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'item_template_list')
	pass

class item_sku():
	api='taobao.item.sku.get'
	def __ini__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',sku_id='',num_iid='',nick=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='properties_name,sku_id,iid,num_iid,properties,\
		quantity,price,outer_id,created,modified,\
		status'
		url=getURL(d)
		return getRes(url)
	def parseItemSku(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'sku')
	pass

class item_skus():
	api='taobao.item.skus.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',num_iids=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='properties_name,sku_id,iid,num_iid,properties,\
		quantity,price,outer_id,created,modified,\
		status'
		url=getURL(d)
		return getRes(url)
	def parseItemSku(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'skus')
	pass

class skus_custom():
	api='taobao.skus.custom.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',outer_id=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='properties_name,sku_id,iid,num_iid,properties,\
		quantity,price,outer_id,created,modified,\
		status'
		url=getURL(d)
		return getRes(url)
	def parseItemSku(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'skus')
	pass

class item():
	api='taobao.item.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session='',format='json'):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=item_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'item')
	pass

class items_custom():
	api='taobao.items.custom.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',outer_id=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=item_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'items')
	pass

class items():
	api='taobao.items.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',
		q='Txu',nicks='',
		cid=None,props=None,
		product_id=None,page_no=None,
		order_by=None,ww_status=None,
		post_fee=None,location.state=None,
		location.city=None,is_3D=None,
		start_score=None,end_score=None,
		start_volume=None,end_volume=None,
		one_station=None,is_cod=None,
		is_cod=None,is_mall=None,
		is_prepay=None,genuine_security=None,
		stuff_status=None,start_price=None,
		end_price=None,page_size=None,
		promoted_service=None,is_xinpin=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=item_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'items')
	pass

class items_inventory():
	api='taobao.items.inventory.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',q='',
		banner='for_shelved',cid='1232',
		seller_cids='12,123',page_no=None,
		page_size='50',has_discount='true',
		order_by='list_time:desc',is_taobao='true',
		is_ex='true',start_modified=None,
		end_modified=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=item_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'items')
	pass

class items_list():
	api='taobao.items.list.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session='',format='json',num_iids=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=item_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'items')
	pass

class items_onsale():
	api='taobao.items.onsale.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session='',format='json',
		q=None,cid='1232',
		seller_cids='12,123',page_no=None,
		has_discount='true',has_showcase='true'
		order_by='list_time:desc',is_taobao='true',
		is_ex='true',start_modified=None,
		end_modified=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=item_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'items')
	pass

class items_search():
	api='taobao.items.search'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json'):
		#TODO params
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='items,item_categories' #TODO
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'item_search')
	pass

class product():
	api='taobao.product.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',product_id='86126527',cid=None,props=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=product_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'product')
	pass

class products():
	api='taobao.products.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',nick='osa品牌服饰旗舰店',page_no=None,page_size=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=product_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'products')
	pass

class products_search():
	api='taobao.products.search'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',
		q='Txu',cid='50011999',
		props=None,status=None,
		page_no=None,page_size=None,
		vertical_market=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=product_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'products')
	pass

class promotion():
	api='taobao.ump.promotion.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session='',format='json',
		item_id='112313',channel_key=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'promotions')
	pass

def main():
	pass

if __name__=='__main__':
	main()
	pass
